package cn.stylefeng.guns.constant;

import cn.stylefeng.guns.modular.constant.entity.Constant;
import cn.stylefeng.guns.modular.constant.service.ConstantService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: ConstanInit
 * @Author liuqiang
 * @Date 2020-02-14 21:57
 */
@Component
@Slf4j
public class ConstanInit  implements CommandLineRunner {

    @Autowired
    private ConstantService constantService;

    @Override
    public void run(String... args) {

        //初始化所有的常量
        List<Constant> list = constantService.list();

        if (list != null && list.size() > 0) {
            for (Constant constant : list) {
                ConstantsHolderContext.putConstant(constant.getCode(), constant.getValue());
            }

            log.info("初始化常量" + list.size() + "条！");
        }

    }
}
